package ch.sv7.tool.dbmanager.db.fix;

import ch.sv7.tool.dbmanager.db.SchemaElement;
import ch.sv7.tool.dbmanager.db.TableSchema;
import ch.sv7.tool.dbmanager.db.dialect.DialectException;

/**
 * TODO: Document me!
 *
 * @author svt
 *
 */
public class CreateTableFix extends AbstractSchemaFix implements SchemaFix {


	private TableSchema tableSchema;

	/**
	 * @param missingTableDifference
	 */
	public CreateTableFix(TableSchema tableSchema) {
		super();
		this.tableSchema = tableSchema;
	}

	public SchemaElement getActionTarget() {
		return tableSchema;
	}
	
	public String getSQLFix() throws DialectException {
		String ddl = "\n-- Create Table Fix \n";
		ddl += getDialect().getCompleteTableDDL(
				tableSchema, 
				true /* primary keys*/, 
				true /* indexes */, 
				false /* foreign keys */,
				true /* constraints*/);
		return ddl;
	}

	public int getPriority() {
		return SchemaFix.PRIORITY_TABLE_CREATION;
	}

	public String getDescription() {
		return "Create table " + tableSchema.getName();
	}

	public int getAction() {
		return ACTION_CREATE;
	}



}
